package com.juphoon.quiz.base.bean;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @Package: net.dopan.pigframe.core.base.controller.response
 * @Title: ResponseBean
 * @Description: 返回数据 响应信息主体
 * @author: 刘宽
 * @date: 2018/8/8 13:07
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ResponseBean<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    @Builder.Default
    public static final int NO_LOGIN = -1;

    @Builder.Default
    public static final int SUCCESS = 0;

    @Builder.Default
    public static final int FAIL = 1;

    @Builder.Default
    public static final int NO_PERMISSION = 2;

    @Builder.Default
    private String msg = "success";

    @Builder.Default
    private int code = SUCCESS;

    private T data;

    public ResponseBean(T data) {
        super();
        this.data = data;
    }

    public ResponseBean(String msg, T data) {
        super();
        this.msg = msg;
        this.data = data;
    }

    public ResponseBean(int code, String msg, T data) {
        super();
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public ResponseBean(Throwable e) {
        super();
        this.msg = e.getMessage();
        this.code = FAIL;
    }

}
